package com.lfd.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.lfd.mapper.ICategoryMapper;
import com.lfd.service.ICategoryService;
import com.lfd.vo.CategoryVo;

@Service
public class ICategoryServiceImpl implements ICategoryService {
	@Autowired
	private ICategoryMapper iCategoryMapper;

	
	/**
	 * 查询分类
	 */
	@Override
	public List<List<CategoryVo>> selectCategoryVos(CategoryVo category) {
		List<List<CategoryVo>> res = new ArrayList();

		List<CategoryVo> selectList = iCategoryMapper.selectCategoryVos(category);
		List<CategoryVo> parent = new ArrayList();
		// 查父类
		for (CategoryVo categoryVo2 : selectList) {
			if (categoryVo2.getParentId()==0) {
				parent.add(categoryVo2);
			}
		}
		// 根据父类查子类添加到返回的LIST中
		for (CategoryVo categoryVo2 : parent) {
			List<CategoryVo> son = new ArrayList();
			for (CategoryVo categoryVo3 : selectList) {
				if (categoryVo2.getCategoryid().equals(categoryVo3.getParentId())) {
					son.add(categoryVo3);
				}
			}
			res.add(son);
		}
		return res;
	}

	
}
